package com.jinbai.servlet.user;

import com.jinbai.service.UserService;
import com.jinbai.view_object.UserVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/studio/user/register.do")
public class RegisterDoServlet extends HttpServlet {
    private final static UserService userService = new UserService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        final String username = req.getParameter("username");
        final String password = req.getParameter("password");

        UserVO userVO = userService.registerUser(username, password);
        final HttpSession session = req.getSession();
        session.setAttribute("currentUser", userVO);
        resp.setCharacterEncoding("utf-8");
        resp.sendRedirect("/studio/user/login.html");
    }
}
